<?php

namespace backend\modules\educater\controllers;

use Yii;
use apiend\components\Controller;
use backend\modules\educater\models\PresidentSearch;
use backend\modules\educater\models\PresidentForm;
use common\models\teacher\Teacher;

/**
 * 校长管理
 * President controller for the `school` module
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class PresidentController extends Controller {

    /**
     * Renders the index view for the module
     * @return string
     */
    public function actionIndex() {

        $searchModel = new PresidentSearch();
        $dataProvider = $searchModel->search(Yii::$app->request->queryParams);

        return $this->render('index', [
            'searchModel' => $searchModel,
            'dataProvider' => $dataProvider,
        ]);
    }

    /**
     * actionCreate
     *
     * @view create.php
     * @return mixed
     */
    public function actionCreate() {
        $model = new PresidentForm();
        $model->scenario = 'create';
        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return $this->redirect(['index']);
        }
        $model->role_id = Teacher::ROLE_ID_PRESIDENT;
        return $this->render('create', [
            'model' => $model
        ]);
    }

    /**
     * actionUpdate
     *
     * @view create.php
     * @return mixed
     */
    public function actionUpdate($id) {
        $model = new PresidentForm($id);
        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return $this->redirect(['index']);
        }
        return $this->render('update', [
            'model' => $model
        ]);
    }

}
